package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.enums.SystemCodeEnum;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.pojo.ParkFeature;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.ParkFeatureService;
import com.tbit.utils.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 站点功能表(ParkFeature)表控制层
 *
 * @author jing
 * @since 2021-03-08 10:46:31
 */
@RestController
@RequestMapping("/parkfeature")
public class ParkFeatureController {
    /**
     * 服务对象
     */
    @Resource
    private ParkFeatureService parkFeatureService;

    /**
     * 通过主键查询单条数据
     *
     * @param parkFeature 主键
     * @return 单条数据
     */
    @PostMapping("/select")
    public JsonResult selectList(ParkFeature parkFeature) {
        Assert.notNull(parkFeature.getParkPointId(), "ver.parkPointId.notNull");
        return JsonResult.ok(this.parkFeatureService.queryById(parkFeature));
    }


    @PostMapping("/add")
    public JsonResult add(ParkFeature parkFeature) {
        Assert.notNull(parkFeature.getParkPointId(), "ver.parkPointId.notNull");
        List<ParkFeature> parkFeatures = parkFeatureService.queryById(new ParkFeature(parkFeature.getParkPointId(), parkFeature.getFeatureType()));
        if (parkFeatures != null && parkFeatures.size() > 0) {
            throw new BaseException(SystemCodeEnum.SITE_FUNCTION_ALREADY_EXISTS);
        }
        parkFeatureService.insert(parkFeature);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    public JsonResult update(ParkFeature parkFeature) {
        parkFeatureService.update(parkFeature);
        return JsonResult.ok();
    }

    @PostMapping("/delete")
    public JsonResult delete(ParkFeature parkFeature) {
        parkFeatureService.delete(parkFeature);
        return JsonResult.ok();
    }

}